package cn.wolfcode.luowowo;

import cn.wolfcode.luowowo.website.interceptor.CheckLoginInterceptor;
import cn.wolfcode.luowowo.website.util.UserInfoArgumentResolver;
import com.alibaba.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

@SpringBootApplication
@EnableDubbo
public class WebSite implements WebMvcConfigurer {
    @Autowired
    private CheckLoginInterceptor checkLoginInterceptor;
    @Autowired
    private UserInfoArgumentResolver resolver;
    //springBoot集成拦截器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //添加拦截的路径和放行的路径
        registry.addInterceptor(checkLoginInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns("/userLogin")
                .excludePathPatterns("/login.html")
                .excludePathPatterns("/userRegist")
                .excludePathPatterns("/regist.html")
                .excludePathPatterns("/sendVerifyCode")
                .excludePathPatterns("/images/**")
                .excludePathPatterns("/js/**")
                .excludePathPatterns("/styles/**");
    }

    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers){
        resolvers.add(resolver);
    }


    public static void main(String[] args) {
        SpringApplication.run(WebSite.class,args);
    }
}
